// 引入ajax请求函数
import {
  reqGuarantee,
  reqCategory
} from '@/api'

// 引入mutation类名
import {
  RECEIVE_GUARANTEE,
  RECEIVE_MENUCATEGORY
} from '../mutation-types'

// 定义state
const state = {
  guarantee: [],
  categories: []
}
// 定义mutation
const mutations = {
  [RECEIVE_GUARANTEE] (state, guarantee) {
    state.guarantee = guarantee
  },
  [RECEIVE_MENUCATEGORY] (state, categories) {
    state.categories = categories
  }
}

// 定义action
const actions = {
  async getGuarantee ({commit, state}) {
    const result = await reqGuarantee()
    const guarantee = result.data
    // console.log(guarantee[0])
    commit(RECEIVE_GUARANTEE, guarantee)
  },
  async getMenuCategory ({commit}) {
    const result = await reqCategory()
    const categories = result.data.kingKongList
    // console.log(categories)
    commit(RECEIVE_MENUCATEGORY, categories)
  }
}

// 定义getters
const getters = {

}

// 暴露各个被定义的模块

export default {
  state,
  mutations,
  actions,
  getters
}
